import 'package:chathouse/pages/expert/buyWallet/recharge_bank_card.dart';
import 'package:chathouse/public/Config.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:chathouse/model/species.dart';
import '../../../model/web_model.dart';
import '../../../util/base_utils.dart';
import '../../../widgets/base_appbar.dart';
import '../../../widgets/base_webview.dart';
import 'bank_transfer_cer_send.dart';

class PayType extends StatefulWidget {
  Rows? row;

  PayType(this.row, {Key? key}) : super(key: key);

  @override
  _PayTypeState createState() => _PayTypeState();
}

class _PayTypeState extends State<PayType> {
  int selectTye = -1;

  String? payUrl;

  Widget item(String imgName, String text, double imgWidth, double imgHeight,
      int type) {
    return InkWell(
      child: Container(
        width: 350.w,
        height: 80.w,
        decoration: BoxDecoration(
          color: selectTye == type ? Styles.c_CCF3A5 : Colors.white,
          border: selectTye == type
              ? const Border()
              : Border.all(width: 1.0, color: Styles.c_B2B1B1),
          borderRadius: BorderRadius.all(Radius.circular(16.w)),
        ),
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            SizedBox(
              width: 88.w,
            ),
            ImageUtils.image(imgName,
                imageType: ImageType.ASSET, width: imgWidth, height: imgHeight),
            SizedBox(
              width: 20.w,
            ),
            Text(text,
                style: getTextStyle(20.sp,
                    fontType: FontType.BOLD, color: Styles.c_191919)),
          ],
        ),
      ),
    ).setOnClickListener(() {
      if (text == "Bank Transfer") {
        Get.to(BanCardRecharge(widget.row));
      }
      if (text == "VISA/Master") {
        var map = {"incomeExpenses": "0", "voucherId": widget.row?.id};
        Obj.showLoading();
        Apis.paymentLinksById(map)
            .then((response) => {
                  Obj.dismissLoading(),
                  payUrl = response?.data["data"]["_links"]["redirect"]["href"],
                  if (!payUrl.isNullOrEmpty)
                    {
                      Get.to(BaseWebViewPage(
                        webModel: WebModel("VISA/Master", payUrl ?? ""),
                      ))
                    }
                })
            .onError((error, stackTrace) => {Obj.dismissLoading()});
      }
    }, isInkWell: true);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: getAppBar(title: "選擇付款方式"),
      body: SafeArea(
        child: Container(
          margin: EdgeInsets.only(top: 50.w),
          width: double.infinity,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              item(Res.expert_visa, "VISA/Master", 37.w, 50.w, 1)
                  .setOnClickListener(() {
                selectTye = 1;
                setState(() {});
              }).setOnClickListener(() {
                selectTye = 1;
                setState(() {});
              }),
              // SizedBox(
              //   height: 12.w,
              // ),
              // item(Res.expert_Bank, "Bank Transfer", 34.w, 34.w, 3)
              //     .setOnClickListener(() {
              //   selectTye = 3;
              //   setState(() {});
              // }),
            ],
          ),
        ),
      ),
    );
  }
}
